#coding=utf-8
'''
Created on
@author: liyinhui
@moduleName: pub.models
@description: 
'''

from django.db import models
from django.contrib import admin
from django.contrib.auth.models import User

import config.constants as constants


#----城市、区县、商圈------------------------------------------
class City(models.Model):
    name = models.CharField('名称', max_length=200)
    pinyin = models.CharField('拼音',max_length=200, help_text="重要！城市的URL依赖此字段")
    is_hot = models.BooleanField('是否热门', default=False)
    class Meta:
        ordering = ['-id']
        verbose_name = '城市'
        verbose_name_plural = '%s管理' % verbose_name
    def __unicode__(self):
        return u'%s' % self.name

class CityAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'pinyin')

admin.site.register(City, CityAdmin)

class Districts(models.Model):
    name = models.CharField('名称', max_length=200)
    city = models.ForeignKey(City, verbose_name='城市')
    class Meta:
        ordering = ['-id']
        verbose_name = '区县'
        verbose_name_plural = '%s管理' % verbose_name

    def __unicode__(self):
        return u'%s' % self.name

    def get_absolute_url(self):
        return 'district/%s/' % self.id

class DistrictsAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'city')

admin.site.register(Districts, DistrictsAdmin)


class BusinessRing(models.Model):
    name = models.CharField('名称', max_length=200)
    district = models.ForeignKey(Districts, verbose_name='区县')
    class Meta:
        ordering = ['-id']
        verbose_name = '商圈'
        verbose_name_plural = '%s管理' % verbose_name
    def __unicode__(self):
        return u'%s' % self.name


class BusinessRingAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'district')

admin.site.register(BusinessRing, BusinessRingAdmin)

#-----用户模型:用户扩展, 相册--------------------------------------------------------
class UserProfile(models.Model):
    '''
    用户信息扩展类, 与Django自带的User类做外键关联
    '''
    from office.models import Office
    from job.models import Company
    user = models.ForeignKey(User, unique=True)
    office = models.ForeignKey(Office, verbose_name="所在写字楼", null=True, blank=True)
    company = models.ForeignKey(Company, verbose_name="所在公司", null=True, blank=True)
    gender = models.CharField('性别', max_length=10, null=True, blank=True)
    birthday = models.CharField('出生日期', max_length=50, null=True, blank=True)
    signature = models.CharField('个性签名', max_length=300, null=True, blank=True)
    subscription = models.BooleanField('是否邮件订阅', default=False)
    give_notice = models.BooleanField('是否提醒', default=False)
    public =  models.BooleanField('是否公开资料', default=False)
    class Meta:
        ordering = ["-id"]
        verbose_name = "用户扩展信息"
        verbose_name_plural = "%s管理" % verbose_name

class UserProfileAdmin(admin.ModelAdmin):
    list_display = ('birthday','signature',)

admin.site.register(UserProfile, UserProfileAdmin)


class UserAlbum(models.Model):
    user = models.ForeignKey(User, verbose_name="用户")
    isTitle = models.CharField("头像?", max_length=10, choices=constants.YESNO_CHOICES)
    src = models.ImageField(upload_to="album",verbose_name="上传图片")
    create_date = models.DateTimeField("上传时间", auto_now=True)
    class Meta:
        ordering = ["-id"]
        verbose_name = "用户图片"
        verbose_name_plural = "%s管理" % verbose_name

class UserAlbumAdmin(admin.ModelAdmin):
    list_display = ("id", "src", "create_date")

admin.site.register(UserAlbum, UserAlbumAdmin)

#----招聘----------------------------------------------------
#class Job(models.Model):
#    company = models.ForeignKey(Company, verbose_name="公司")
#    title = models.CharField("标   题", max_length=100)
#    is_top = models.CharField("是否置顶", max_length=10, choices=constants.YESNO_CHOICES)
#    is_rapid = models.CharField("是否急聘", max_length=10, choices=constants.YESNO_CHOICES)
#    category = models.CharField("职位类别", max_length=100, null=True, blank=True)
#    kind = models.CharField("职位性质", max_length=100, null=True, blank=True)
#    experience = models.CharField("经验要求", max_length=100, null=True, blank=True)
#    degree = models.CharField("学历要求", max_length=100, null=True, blank=True)
#    number = models.CharField("招聘人数", max_length=100, null=True, blank=True)
#    salary = models.CharField("月   薪", max_length=100)
#    place = models.CharField("工作地点", max_length=100)
#    end_date = models.DateField("截止日期", auto_now=False)
#    create_date = models.DateField("发布日期", auto_now=True)
#    about = models.TextField("职位描述及其它要求", max_length=100, null=True, blank=True)
#
#    class Meta:
#        ordering = ["-is_top","-id"]
#        verbose_name = "公司招聘"
#        verbose_name_plural = "%s管理" % verbose_name
#
#class JobAdmin(admin.ModelAdmin):
#    list_display = ("id","is_top","company","title","salary","create_date","end_date")
#
#admin.site.register(Job, JobAdmin)


#----Sale,Buy的抽象父类-------------------------------------------
#class SaleBuyAbstract(models.Model):
#    office = models.ForeignKey(Office, verbose_name="所在写字楼", null=True, blank=True)
#    user = models.ForeignKey(User,verbose_name="发布人", null=True, blank=True)
#    title = models.CharField("标   题", max_length=100)
#    audit_status = models.CharField("审核状态", max_length=10, choices=constants.AUDIT_CHOICES)
#    is_top = models.CharField("是否置顶", max_length=10, choices=constants.YESNO_CHOICES)
#    address = models.CharField("物业地址", max_length=200)
#    acreage = models.CharField("面   积", max_length=200)
#    price = models.CharField("报价(元/平米)", max_length=200)
#    linkman = models.CharField("联系人", max_length=200)
#    telephone = models.CharField("联系电话", max_length=200)
#    create_date = models.DateField("发布日期", auto_now=True)
#    end_date = models.DateField("截止日期", auto_now=False)
#    about = models.TextField("其它附加信息", max_length=1000, null=True, blank=True)
#
#    class Meta:
#        abstract = True
        
#----出租或出售-------------------------------------------
#class Sale(SaleBuyAbstract):
#    types = models.CharField("类   型", max_length=10, choices=constants.SALE_TYPE_CHOICES)
#    class Meta:
#        ordering = ["-is_top","-id"]
#        verbose_name = "出租或出售"
#        verbose_name_plural = "%s管理" % verbose_name
#
#class SaleAdmin(admin.ModelAdmin):
#    list_display = ("id","user","is_top","types","office","title","create_date","end_date")
#
#admin.site.register(Sale, SaleAdmin)


#----求租或求购-------------------------------------------
#class Buy(SaleBuyAbstract):
#    types = models.CharField("类   型", max_length=10, choices=constants.BUY_TYPE_CHOICES)
#    class Meta:
#        ordering = ["-is_top","-id"]
#        verbose_name = "求租或求购"
#        verbose_name_plural = "%s管理" % verbose_name
#
#class BuyAdmin(SaleAdmin):
#    pass

#admin.site.register(Buy, BuyAdmin)

#-----周边商户-------------------------------------------
#class Store(models.Model):
#    office = models.ForeignKey(Office, verbose_name="所在写字楼", null=True, blank=True)
#    name = models.CharField("商户名称", max_length=100)
#    address = models.CharField("详细地址", max_length=200, null=True, blank=True)
#    telephone = models.CharField("联系电话", max_length=100, null=True, blank=True)
#    shop_hours = models.CharField("营业时间", max_length=100, null=True, blank=True)
#    avg_consume = models.CharField("人均消费", max_length=100, null=True, blank=True)
#    star_level = models.CharField("评分等级", max_length=100, null=True, blank=True)
#    status = models.CharField("商户状态", max_length=10, choices=constants.STORE_STATUS_CHOICES)
#    close_reason = models.CharField("关闭原因", max_length=100, null=True, blank=True)
#    bus = models.CharField("公交信息", max_length=500, null=True, blank=True)
#    create_date = models.DateTimeField("发布日期", auto_now=True)
#
#    class Meta:
#        ordering = ["-id"]
#        verbose_name = "商户"
#        verbose_name_plural = "%s管理" % verbose_name
#
#class StoreAdmin(admin.ModelAdmin):
#    list_display = ("id","office","name","telephone","avg_consume","status","create_date")
#
#admin.site.register(Store, StoreAdmin)

#-----商户相册---------------------------------------------------------
#class StoreAlbum(BaseAlbum):
#    store = models.ForeignKey(Store, verbose_name="商户")
#    class Meta:
#        ordering = ["-id"]
#        verbose_name = "商户图片"
#        verbose_name_plural = "%s管理" % verbose_name
#
#class StoreAlbumAdmin(admin.ModelAdmin):
#    list_display = ("id","store", "src", "create_date")
#
#admin.site.register(StoreAlbum, StoreAlbumAdmin)

#----商户点评-------------------------------------------
#class Comment(models.Model):
#    office = models.ForeignKey(Office, verbose_name="所在写字楼")
#    user = models.ForeignKey(User,verbose_name="点评人")
#    note = models.TextField("详细点评", max_length=1000)
#    avg_consume = models.CharField("人均消费(元/人)", max_length=100)
#    star_level = models.CharField("消费评级", max_length=100)
#    flower = models.IntegerField("送花数量", default=0, null=True, blank=True)
#    create_date = models.DateTimeField("发布日期", auto_now=True)
#
#    class Meta:
#        ordering = ["-id"]
#        verbose_name = "商户点评"
#        verbose_name_plural = "%s管理" % verbose_name
#
#class CommentAdmin(admin.ModelAdmin):
#    list_display = ("id","office","user","avg_consume","star_level","flower","create_date")
#
#admin.site.register(Comment, CommentAdmin)

#-------点评相册-------------------------------------------
#class CommentAlbum(BaseAlbum):
#    comment = models.ForeignKey(Comment, verbose_name="点评")
#    class Meta:
#        ordering = ["-id"]
#        verbose_name = "点评图片"
#        verbose_name_plural = "%s管理" % verbose_name
#
#class CommentAlbumAdmin(admin.ModelAdmin):
#    list_display = ("id","comment", "src", "create_date")
#
#admin.site.register(CommentAlbum, CommentAlbumAdmin)


#----点评回复-------------------------------------------
#class CommentReply(models.Model):
#    comment = models.ForeignKey(Comment, verbose_name="点评")
#    user = models.ForeignKey(User,verbose_name="回复人")
#    note = models.TextField("回复内容", max_length=1000)
#    create_date = models.DateTimeField("回复时间", auto_now=True)
#
#    class Meta:
#        ordering = ["-id"]
#        verbose_name = "点评回复"
#        verbose_name_plural = "%s管理" % verbose_name
#
#class CommentReplyAdmin(admin.ModelAdmin):
#    list_display = ("id","comment","user","note","create_date")
#
#admin.site.register(CommentReply, CommentReplyAdmin)


#---系统参数配置------------------------------------------------------
#class SysParam(models.Model):
#    name = models.CharField("配置项名称", max_length=200)
#    value = models.CharField("配置值", max_length=200)
#    comment = models.TextField("备注", max_length=1000)
#    class Meta:
#        ordering = ["-id"]
#        verbose_name_plural = "网站参数配置"
#
#class SysParamAdmin(admin.ModelAdmin):
#    list_display = ("id","name", "value", "comment")
#
#admin.site.register(SysParam, SysParamAdmin)
